#include "common/config/config.h"
#include "common/log/log.h"

#include "edge.h"

namespace F2FB
{

namespace Database
{

std::vector<unsigned> Edge::ids(
    sqlite::database& database
)
{
    std::vector<unsigned> result;
    database << "SELECT id FROM edges;"
        >> [&result](unsigned id)
    {
        result.emplace_back(id);
    };
    return result;
}

std::vector<std::shared_ptr<Entity>> Edge::entities(
    sqlite::database& database
)
{
    const auto sqlStr = "SELECT "
                        "  id "
                        ", from_state_id "
                        ", to_state_id "
                        "FROM edges;";

    auto query = database << sqlStr;
    std::vector<std::shared_ptr<Entity>> result;
    query >>
        [&result](
            unsigned id,
            unsigned fromStateId,
            unsigned toStateId
        )
    {
        auto entity = std::make_shared<Edge>();
        entity->m_data["id"] = id;
        entity->m_data["from_state_id"] = fromStateId;
        entity->m_data["to_state_id"] = toStateId;
        result.push_back(entity);
    };
    return result;
}

} // namespace Database

} // namespace F2FB
